<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 16/4/17
 * Time: 下午2:22
 * Describe:
 */

namespace liketry\controllers;

use Yii;

use services\models\MemberInfo;

class MemberInfoController extends CustomController
{

    /**
     * @param int $cell
     * @return array
     */
    public function actionCellGetCode($cell = 0)
    {
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        $member_no = \Yii::$app->session->get(\Yii::$app->params['member_no'], 0);
        if (!$member_no) {
            return ['flag' => false, 'msg' => '用户未登录, 不能验证'];
        }

        /** @var MemberInfo $member */
        $member = MemberInfo::find()->getByPrimary($member_no);

        if (!$member->cellConfirmProc($cell)) {
            return ['flag' => false, 'msg' => $member->getFirstError('cell')];
        }
        return ['flag' => true, 'msg' => $member->getFirstError('cell')];


    }

    public function actionCellConfirm($cell = null, $cellCode)
    {


        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

        $member_no = \Yii::$app->session->get(\Yii::$app->params['member_no'], 0);

        if (!$member_no) {
            return ['flag' => false, 'msg' => '用户未登录, 不能验证'];
        }
        /** @var MemberInfo $member */
        $member = MemberInfo::find()->getByPrimary($member_no);

        $result = $member->cellConfirmProc($cell, $cellCode);

        return ['flag' => $result, 'msg' => $member->getFirstError('cell')];


    }

}